package com.example.studymoudle;

import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.widget.EditText;

import androidx.appcompat.app.AppCompatActivity;

import com.example.studymoudle.decorator_design_pattern.BasePizza;
import com.example.studymoudle.decorator_design_pattern.Pizza;
import com.example.studymoudle.decorator_design_pattern.PizzaA;
import com.example.studymoudle.decorator_design_pattern.PizzaC;
import com.example.studymoudle.observer_design_pattern.Emitter;
import com.example.studymoudle.observer_design_pattern.Function;
import com.example.studymoudle.observer_design_pattern.Observable;
import com.example.studymoudle.observer_design_pattern.ObservaleOnSubscribe;
import com.example.studymoudle.observer_design_pattern.Observer;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //观察者模式
        Observable.create(new ObservaleOnSubscribe<String>() {

            @Override
            public void subscribe(Emitter<String> emitter) {
                emitter.onNext("大家好");
            }
        }).map(new Function<String, String>() {
            @Override
            public String apply(String s) {
                s= s+"888";
                return s;
            }
        }).subscribe(new Observer() {
            @Override
            public void onSubscribe() {

            }

            @Override
            public void onNext(Object o) {
                Log.e("log--------------",(String) o+"");
            }

            @Override
            public void onError(Throwable e) {

            }

            @Override
            public void onComplete() {

            }
        });

        //装饰器模式
        Pizza x = new BasePizza();
        PizzaA p = new PizzaA(new PizzaC(x));

        p.show();


        EditText editText = new EditText(MainActivity.this);

        Observable.create(new ObservaleOnSubscribe<Object>() {
            @Override
            public void subscribe(Emitter<Object> e) {
                editText.addTextChangedListener(new TextWatcher() {
                    @Override
                    public void beforeTextChanged(CharSequence s, int start, int count, int after) {

                    }

                    @Override
                    public void onTextChanged(CharSequence s, int start, int before, int count) {
                        e.onNext(s.toString());
                    }

                    @Override
                    public void afterTextChanged(Editable s) {

                    }
                });
            }
        });





    }
}